import { createRouter, createWebHashHistory } from 'vue-router'
import App from '@/App.vue'
import { getToken, LOCAL_WX } from "../utils/user"

// 路由规则
const routes = [
  {
    path: '/',
    component: App,
    children: [
      { path: '', redirect: '/login' },
      {
        path: '/login/:id?',
        name: 'login',
        component: () => import('@/views/Login.vue')
      },
      {
        path: '/Registe/',
        name: 'Registe',
        component: () => import('@/views/Registe.vue')
      },
      {
        path: '/index/',
        name: 'index',
        component: () => import('@/views/Index.vue')
      },
      {
        path: '/ChatList/',
        name: 'ChatList',
        component: () => import('@/views/ChatList.vue')
      },
      {
        path: '/Chat/:id?',
        name: 'Chat',
        component: () => import('@/views/Chat.vue')
      },
      {
        path: '/HuiZhen/',
        name: 'HuiZhen',
        component: () => import('@/views/HuiZhen.vue')
      },

      {
        path: '/KeYan/',
        name: 'KeYan',
        component: () => import('@/views/KeYan.vue')
      },
      {
        path: '/Patients/',
        name: 'Patients',
        component: () => import('@/views/Patients.vue')
      },
      {
        path: '/Patient/:id?',
        name: 'Patient',
        component: () => import('@/views/Patient.vue')
      },
      {
        path: '/PatientDetail/',
        name: 'PatientDetail',
        component: () => import('@/views/PatientDetail.vue')
      },
      {
        path: '/LiangBiao/:id?',
        name: 'LiangBiao',
        component: () => import('@/views/LiangBiao.vue')
      },
      {
        path: '/KeYan/:id?',
        name: 'KeYan',
        component: () => import('@/views/KeYan.vue')
      },
      {
        path: '/PatientKy/:id?',
        name: 'PatientKy',
        component: () => import('@/views/PatientKy.vue')
      },
      {
        path: '/DocKy/',
        name: 'DocKy',
        component: () => import('@/views/DocKy.vue')
      },
      {
        path: '/MyKy/',
        name: 'MyKy',
        component: () => import('@/views/MyKy.vue')
      },
      {
        path: '/OtherKy/',
        name: 'OtherKy',
        component: () => import('@/views/OtherKy.vue')
      },
      {
        path: '/KyDetail/:id?',
        name: 'KyDetail',
        component: () => import('@/views/KyDetail.vue')
      },
      {
        path: '/KySolution/:id?',
        name: 'KySolution',
        component: () => import('@/views/KySolution.vue')
      },
      {
        path: '/KyDoc/:id?',
        name: 'KyDoc',
        component: () => import('@/views/KyDoc.vue')
      },
      {
        path: '/KyPatient/:id?',
        name: 'KyPatient',
        component: () => import('@/views/KyPatient.vue')
      },
      {
        path: '/KyList/',
        name: 'KyList',
        component: () => import('@/views/KyList.vue')
      },
      {
        path: '/Share/',
        name: 'Share',
        component: () => import('@/views/Share.vue')
      },
      {
        path: '/Team/',
        name: 'Team',
        component: () => import('@/views/Team.vue')
      },

      {
        path: '/Tool/',
        name: 'Tool',
        component: () => import('@/views/Tool.vue')
      },
      {
        path: '/JieSuan/',
        name: 'JieSuan',
        component: () => import('@/views/JieSuan.vue')
      },
      {
        path: '/QianShu/:id?',
        name: 'QianShu',
        component: () => import('@/views/QianShu.vue')
      },
      {
        path: '/Video/',
        name: 'Video',
        component: () => import('@/views/Video.vue')
      },
      {
        path: '/XuQiu/',
        name: 'XuQiu',
        component: () => import('@/views/XuQiu.vue')
      },
      {
        path: '/ZhuanZhen/',
        name: 'ZhuanZhen',
        component: () => import('@/views/ZhuanZhen.vue')
      },
    ]
  }
]

const router = createRouter({
  // vueRouter@3版本的mode改成了history，hash模式配置createWebHashHistory，history模式配置createWebHistory
  history: createWebHashHistory(),
  routes
})


router.beforeEach((to, from, next) => {
  // const token = getToken();

  // if (!token && to.path !== '/login') {
  //   let checkWx = localStorage.getItem(LOCAL_WX)
  //   if (!checkWx) {
  //     next('/login');
  //   } else {
  //     //微信登录
  //     next()
  //   }
  // } else {
  //   next();
  // }

  next()
});

export default router